#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countSum(int n)
    {
        if (n == 0)
            return 0;
        else
            return countSum(n / 10) + n % 10;
    }
    int countLargestGroup(int n) {
        unordered_map<int, int> diff;
        for (int i = 1; i <= n; i++)
        {
            diff[countSum(i)]++;
        }
        int mmax = 0, res = 0;
        for (auto& [x, y] : diff)
        {
            if (y > mmax)
            {
                res = 1;
                mmax = y;
            }
            else if (y == mmax)
                ++res;
        }
        return res;
    }
};